package com.binfenhulian.chinaenergy.ces.manage.service.readedit;

import com.binfenhulian.chinaenergy.ces.core.bean.enums.ExceptionDescEnum;
import com.binfenhulian.chinaenergy.ces.core.exception.BaseException;
import com.binfenhulian.chinaenergy.ces.manage.core.db.dao.auto.UseLogDAO;
import com.binfenhulian.chinaenergy.ces.manage.core.db.dao.def.ReadEditLogDefDAO;
import com.binfenhulian.chinaenergy.ces.manage.core.db.enums.LogStatusEnum;
import com.binfenhulian.chinaenergy.ces.manage.core.db.po.auto.ImportLogPO;
import com.binfenhulian.chinaenergy.ces.manage.core.db.po.auto.UseLogPO;
import com.binfenhulian.chinaenergy.ces.utils.date.UnixTimestampUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by wanghjbuf on 2018/3/15.
 */
@Service("com.binfenhulian.chinaenergy.ces.manage.service.readedit.ReadEditServiceImpl")
public class ReadEditServiceImpl implements ReadEditService{

    @Autowired
    ReadEditLogDefDAO readEditLogDefDAO;
    @Autowired
    UseLogDAO useLogDAO;

    @Override
    public PageInfo listReadEditLogByPage(Map<String,Object> paramMap) throws BaseException {
        try {
            Page page = PageHelper.startPage(Integer.parseInt(paramMap.get("pageNum").toString()), Integer.parseInt(paramMap.get("pageSize").toString()));
            PageInfo pageInfo = new PageInfo(readEditLogDefDAO.query(paramMap));
            return pageInfo;
        } catch (Exception e) {
            throw new BaseException("系统未知错误,操作失败!", e);
        }
    }

    @Override
    public int add(String recordNo, String account) throws BaseException {
        try {
            UseLogPO useLogPO = new UseLogPO();
            useLogPO.setAccount(account);
            useLogPO.setRecordNo(recordNo);
            useLogPO.setCreateTime(UnixTimestampUtils.currentTimes());
            useLogPO.setStatus(LogStatusEnum.INIT.name());
            return useLogDAO.insertSelective(useLogPO);
        }catch (Exception e){
            throw new BaseException(ExceptionDescEnum.BASE.getExceptionDesc(), e);
        }
    }
}